<template>
  <div style="display: flex;align-items: center;justify-content: center;margin-top: 30px">
    <div class="tree">
      <!--彩灯-->
      <div
          class="lamp"
          :style="'--fromColor:'+color[color.length-1 - 0]+';--itemColor:'+color[0]+';'">
      </div>
      <div
          class="lamp"
          :style="'--fromColor:'+color[color.length-2 - 1]+';--itemColor:'+color[1]+';'">
      </div>
      <div
          class="lamp"
          :style="'--fromColor:'+color[color.length-3 - 2]+';--itemColor:'+color[2]+';'">
      </div>
      <div
          class="lamp"
          :style="'--fromColor:'+color[color.length-4 - 3]+';--itemColor:'+color[3]+';'">
      </div>
      <div
          class="lamp"
          :style="'--fromColor:'+color[6]+';--itemColor:'+color[0]+';'">
      </div>
      <div
          class="lamp"
          :style="'--fromColor:'+color[7]+';--itemColor:'+color[1]+';'">
      </div>
      <div
          class="lamp"
          :style="'--fromColor:'+color[3]+';--itemColor:'+color[4]+';'">
      </div>
      <div class="star">
        <div class="star-in"></div>
      </div>
      <!--树叶-->
      <div class="leaf-box">
        <div class="leaf">
          <div class="edge"></div>
          <div class="edge right"></div>
        </div>
        <div class="leaf">
          <div class="edge"></div>
          <div class="edge right"></div>
        </div>
        <div class="leaf">
          <div class="edge"></div>
          <div class="edge right"></div>
        </div>
        <div class="leaf">
          <div class="edge"></div>
          <div class="edge right"></div>
        </div>
        <div class="leaf">
          <div class="edge"></div>
          <div class="edge right"></div>
        </div>
      </div>
      <!--树干-->
      <div class="trunk"></div>

    </div>
  </div>
</template>

<script setup>
const color = ref(['#E6A23C', '#f3cb85', '#E65D6E', 'greenyellow',
  '#9932CC', '#DDA0DD', '#EEE8AA', '#EEE8AA'])
</script>

<style scoped lang="scss">
body {
  background-color: #020024;
}

/*圣诞树外层div*/
.tree {
  width: 200px;
  height: 300px;
  margin: 80px auto 0 auto;
  position: relative;
}

.star {
  width: 50px;
  height: 50px;
  position: absolute;
  background-color: #fff;
  border-radius: 50%;
  top: -25px;
  z-index: 1000;
  left: 50%;
  transform: translateX(-50%);
  animation: starLight 1.5s ease infinite alternate;
}

.star-in {
  position: absolute;
  left: 50%;
  top: 50%;
  border-right: 100px solid transparent;
  border-bottom: 70px solid gold;
  border-left: 100px solid transparent;
  transform: translateX(-50%) translateY(-50%) rotate(35deg) scale(0.14);
}

.star-in:before {
  border-bottom: 80px solid gold;
  border-left: 30px solid transparent;
  border-right: 30px solid transparent;
  position: absolute;
  top: -45px;
  left: -65px;
  content: '';
  transform: rotate(-35deg);
}

.star-in:after {
  border-bottom: 70px solid gold;
  border-left: 100px solid transparent;
  border-right: 100px solid transparent;
  position: absolute;
  top: 3px;
  left: -105px;
  content: '';
  transform: rotate(-70deg);
}

@keyframes starLight {
  0% {
    background: radial-gradient(ellipse at center,
        gold 0%, rgba(255, 240, 158, 0.5) 42%,
        rgba(255, 242, 173, 0.2) 58%,
        rgba(255, 255, 255, 0.1) 100%);
  }
  25% {
    background: radial-gradient(ellipse at center, gold 0%,
        rgba(255, 240, 158, 0.5) 40%,
        rgba(255, 242, 173, 0.2) 60%,
        rgba(255, 255, 255, 0.1) 100%);
  }
  50% {
    background: radial-gradient(ellipse at center,
        gold 0%, rgba(255, 240, 158, 0.5) 38%,
        rgba(255, 242, 173, 0.2) 62%,
        rgba(255, 255, 255, 0.1) 100%);
  }
  75% {
    background: radial-gradient(ellipse at center,
        gold 0%, rgba(255, 240, 158, 0.5) 36%,
        rgba(255, 242, 173, 0.2) 64%,
        rgba(255, 255, 255, 0.1) 100%);
  }
  100% {
    background: radial-gradient(ellipse at center,
        gold 0%, rgba(255, 240, 158, 0.5) 34%,
        rgba(255, 242, 173, 0.2) 66%,
        rgba(255, 255, 255, 0.1) 100%);
  }
}

.leaf {
  position: absolute;
  left: 50%;
  top: 3%;
  margin-left: -30px;
  background-color: rgba(14, 110, 14);
  width: 60px;
  height: 60px;
  border-radius: 0 10px 35px 10px;
  transform: rotate(45deg);
  box-shadow: 2px 7px 2px rgba(43, 43, 43, 0.2);
}

.edge {
  position: absolute;
  left: 0;
  bottom: 0;
  background: rgba(14, 110, 14);
  width: 25px;
  height: 30px;
  border-radius: 0 10px 35px 10px;
  transform: translateY(50%) translateX(0);
}

.edge.right {
  position: absolute;
  left: unset;
  bottom: unset;
  top: 0;
  right: 0;
  background: rgba(14, 110, 14);
  width: 25px;
  height: 30px;
  border-radius: 0 10px 35px 10px;
  transform: translateY(0) translateX(50%);
}

/*双数修改背景色*/
.leaf:nth-child(even) {
  background-color: #0f880f;
}

.leaf:nth-child(even) .edge {
  background-color: #0f880f;
}

/*最上面*/
.leaf:nth-child(1) {
  z-index: 100;
  transform: rotate(45deg) scale(0.8);
}

/*第二*/
.leaf:nth-child(2) {
  z-index: 99;
  top: 15%;
  transform: rotate(45deg) scale(1.3);
}

.leaf:nth-child(3) {
  z-index: 98;
  top: 28%;
  transform: rotate(45deg) scale(1.6);
}

.leaf:nth-child(4) {
  z-index: 97;
  top: 41%;
  transform: rotate(45deg) scale(1.9);
}

.leaf:nth-child(5) {
  z-index: 96;
  top: 54%;
  transform: rotate(45deg) scale(2.2);
}

.trunk {
  width: 25px;
  height: 45px;
  border-radius: 0 0 3px 3px;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 20px;
  z-index: 1;
  box-shadow: 0 0 10px 5px rgb(19, 19, 19);
  background: linear-gradient(0deg, #6d411b 0%, #5a341d 64%);
}


.lamp {
  z-index: 1000;
  position: absolute;
  list-style: none;
  margin: 0;
  padding: 0;
  width: 12px;
  height: 28px;
  border-radius: 50%;
  display: inline-block;
  margin: 20px;
  box-shadow: 0px 4px 24px 3px var(--itemColor);
  background: var(--itemColor);
  animation: flash 1s linear infinite;
}

.lamp:after {
  content: "";
  position: absolute;
  top: -13px;
  left: 4px;
  width: 18px;
  height: 18px;
  border-radius: 30%;
  z-index: -1;
}

.lamp:before {
  content: "";
  position: absolute;
  background: red;
  width: 11px;
  height: 10px;
  border-radius: 3px;
  top: -4px;
  left: 1px;
}

.lamp:nth-child(1) {
  left: 60px;
  top: 20px;
}

.lamp:nth-child(1):after {
  border-left: solid red 2px;
}

.lamp:nth-child(2) {
  left: 45px;
  top: 80px;
}

.lamp:nth-child(2):after {
  border-left: solid red 2px;
}

.lamp:nth-child(3) {
  left: 10px;
  top: 160px;
}

.lamp:nth-child(3):after {
  border-left: solid red 2px;
}


.lamp:nth-child(4) {
  right: 60px;
  top: 30px;
}

.lamp:nth-child(4):after {
  border-right: solid red 2px;
  left: -10px !important;
}

.lamp:nth-child(5) {
  right: 40px;
  top: 80px;
}

.lamp:nth-child(5):after {
  border-right: solid red 2px;
  left: -10px !important;
}

.lamp:nth-child(6) {
  right: 10px;
  top: 160px;
}

.lamp:nth-child(6):after {
  border-right: solid red 2px;
  left: -10px !important;
}


.lamp:nth-child(7) {
  right: 75px;
  top: 145px;
}

.lamp:nth-child(7):after {
  border-right: solid red 2px;
  left: -10px !important;
}


@keyframes flash {
  0%,
  100% {
    background: var(--itemColor);
    box-shadow: 0px 4px 24px 3px var(--itemColor);
  }
  50% {
    background: var(--fromColor);
    box-shadow: 0px 4px 24px 3px var(--fromColor);
  }
}
</style>